package com.tool4j.controller;

import com.tool4j.entity.ChatCollection;
import com.tool4j.service.ChatCollectionService;
import com.tool4j.util.UserPermission;
import com.tool4j.util.http.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;

import java.util.List;

@RestController
@RequestMapping("/api/collection")
public class ChatCollectionController {

    @Autowired
    private ChatCollectionService collectionService;

    @PostMapping("/submit")
    public Result<Void> submit(ServerWebExchange exchange, @RequestBody ChatCollection params) {
        params.setUserId(UserPermission.get(exchange).getUserId());
        collectionService.saveData(params);
        return Result.ok();
    }

    @PostMapping("/findList")
    public Result<List<ChatCollection>> findList(ServerWebExchange exchange, @RequestBody ChatCollection params) {
        params.setUserId(UserPermission.get(exchange).getUserId());
        return Result.ok(collectionService.findList(params));
    }

}
